package com.omesoft.hksnore.util.myactivity;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;

import com.omesoft.hksnore.R;
import com.omesoft.hksnore.util.CustomToast;
import com.omesoft.hksnore.util.web.CheckNetwork;
import com.omesoft.hksnore.util.web.HttpUtil;
import com.umeng.analytics.MobclickAgent;

public class MyActivity extends Activity {

    protected Context context;

    protected int anim = -1;// 跳转动画选择
    // 动画常量
    /**
     * 退出动画-向左
     */
    protected final static int OANIM2L = 1;
    /**
     * 退出动画-向右
     */
    protected final static int OANIM2R = 2;
    /**
     * 退出动画-向下
     */
    protected final static int OANIM2B = 3;

    protected Activity activity;
    protected Handler handler;
    protected  String currentIP;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
        context = this;
        activity = this;
        getIp();
        MobclickAgent.setDebugMode(true);
        // SDK在统计Fragment时，需要关闭Activity自带的页面统计，
        // 然后在每个页面中重新集成页面统计的代码(包括调用了 onResume 和 onPause 的Activity)。
        MobclickAgent.openActivityDurationTrack(false);
        // MobclickAgent.setAutoLocation(true);
        // MobclickAgent.setSessionContinueMillis(1000);
        // MobclickAgent.startWithConfigure(
        // new UMAnalyticsConfig(mContext, "4f83c5d852701564c0000011", "Umeng",
        // EScenarioType.E_UM_NORMAL));
        MobclickAgent.setScenarioType(context, MobclickAgent.EScenarioType.E_UM_NORMAL);
    }

    private void getIp() {
        if (CheckNetwork.checkNetwork3(this)){
            new Thread(){
                public void run(){
                    try{
                      currentIP = HttpUtil.GetNetIp(context);
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }
            }.start();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }


    protected void init() {

    }

    protected void initView() {

    }

    protected void loadView() {

    }

    protected void initTitleBar() {

    }

    protected void initTitle() {
    }

    protected void showToast(String text) {
        CustomToast.showToasts(context, text);
    }

    protected void showToast(int text) {
        CustomToast.showToasts(context, text);
    }

    protected void initHandler() {
        // TODO Auto-generated method stub
    }

    @Override
    public void finish() {
        super.finish();
        loadAnim();
    }

    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        anim = 2;
        finish();
    }

    protected void loadAnim() {
        switch (anim) {
            case OANIM2L:
                // 向左
                overridePendingTransition(R.anim.in_righttoleft, R.anim.out_righttoleft);
                break;
            case OANIM2R:
                // 向右
                overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
                break;
            default:
                overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
                break;
        }
    }

    /**
     * 统一 跳转activity 方法
     *
     * @param classActivity
     */
    public void jumpActivity(final Context context, final Class<?> classActivity) {
        anim = 1;
        startActivity(new Intent(context, classActivity));
        finish();
    }
    /**
     * 统一 跳转activity 方法
     *
     * @param classActivity
     */
    public void jumpActivity2(final Context context, final Class<?> classActivity) {
        anim = 2;
        startActivity(new Intent(context, classActivity));
        finish();
    }

    /**
     * 统一 跳转activity 方法
     *
     * @param classActivity
     */
    public void jumpActivityNotFinish(final Context context, final Class<?> classActivity) {
        anim = 1;
        startActivity(new Intent(context, classActivity));
        loadAnim();
    }

    public static int getAndroidSDKVersion() {
        int version = 0;
        try {
            version = Integer.valueOf(android.os.Build.VERSION.SDK);
        } catch (NumberFormatException e) {
        }
        return version;
    }

    protected void sendMsg(Handler handler, int whatId, Object objs) {
        Message msg = Message.obtain();
        msg.what = whatId;
        msg.obj = objs;
        Log.v("sendMsg", "msg.what=" + msg.what);
        if (handler != null) {
            handler.sendMessage(msg);
        }
    }

    protected void sendMsg(int whatId, Object objs) {
        Message msg = Message.obtain();
        msg.what = whatId;
        msg.obj = objs;
        Log.v("sendMsg", "msg.what=" + msg.what);
        if (handler != null) {
            handler.sendMessage(msg);
        }
    }

    protected void sendMsg(int whatId) {
        Message msg = Message.obtain();
        msg.what = whatId;
        Log.v("sendMsg", "msg.what=" + msg.what);
        if (handler != null) {
            handler.sendMessage(msg);
        }
    }

    /**
     * 版本号
     *
     * @return
     */
    public static int getSDKVersionNumber() {
        int sdkVersion;
        try {
            sdkVersion = Integer.valueOf(android.os.Build.VERSION.SDK);
        } catch (NumberFormatException e) {
            sdkVersion = 0;
        }
        return sdkVersion;
    }
}

